home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
tex
/
gestalt.zip
/
SIMIL_P.OBJ
< prev
Wrap
Text File
|
1988-12-06
|
17KB
|
259 lines
Inline(
{;From the article "Pattern Matching - The Gestalt Approach"}
{;by John W. Ratcliff and David E. Metzener}
{;Dr. Dobbs Journal, July 1988}
{;Rewritten for Turbo Pascal v3.0 inline code and INLINE.COM.}
{;Now expects normal Pascal strings (first byte is length byte).}
{;Usage:}
{;}
{;FUNCTION Simil(VAR Str1,Str2) : INTEGER;}
{; VAR result : INTEGER;}
{; BEGIN}
{; (*$I simil_p.obj*) (* this code *)}
{; Simil := result; (*return the function result*)}
{; END; (* of Simil *)}
{;}
{;See TESTSIM.PAS for required global variables.}
{;}
{;Extensive remarks removed. See other versions.}
{; David Kirschbaum}
{; Toad Hall}
{; kirsch@braggvax.ARPA}
$55 { push bp ;save Turbo's BP}
/$06 { push ES ;and ES}
/$FC { cld ;insure forward}
/$C4/$B6/>STR1 { les si,>str1[bp] ;ES:SI = str1 addr}
/$8B/$BE/>STR2 { mov di,>str2[bp] ;ES:DI = str2 addr}
{;}
/$31/$C0 { xor ax,ax ;get a 0}
/$A3/>SCORE { mov [>score],ax ;zero out SCORE}
/$A3/>STCKNUM { mov [>stcknum],ax ;init nr of stack entries to 0}
/$26 { ES:}
/$38/$04 { cmp [si],al ;is it a null string?}
/$74/$05 { je StrErr ;can't process null strings}
/$26 { ES:}
/$38/$05 { cmp [di],al ;is it a null string?}
/$75/$03 { jne DoCmp ;Both strs ok, so process them}
{StrErr:}
/$E9/$4E/$01 { jmp Exit ;exit routine}
{;}
{DoCmp:}
/$30/$E4 { xor ah,ah ;clear msb}
/$26 { ES:}
/$8A/$04 { mov al,[si] ;get str1 length byte}
/$89/$C1 { mov cx,ax ;accum total len in CX}
/$01/$F0 { add ax,si ;add in string start}
/$89/$C3 { mov bx,ax ;BX points to str1 last char}
/$46 { inc si ;bump SI past str1 length byte}
{;}
/$30/$E4 { xor ah,ah ;clear msb}
/$26 { ES:}
/$8A/$05 { mov al,[di] ;str2 length byte}
/$01/$C1 { add cx,ax ;accum total len in CX}
/$01/$F8 { add ax,di ;add in start}
/$89/$C5 { mov bp,ax ;BP points to str2 last char}
/$47 { inc di ;bump DI past str2 length byte}
{;}
/$89/$0E/>TOTAL { mov [>total],cx ;store total string length}
{;}
/$E8/$ED/$00 { call PushSt ;push values for}
{; ; first call to SIMILIARITY}
{Main:}
/$81/$3E/>STCKNUM/$00/$00{ cmp word [>stcknum],0 ;anything on the stack?}
/$74/$76 { je Done ;no, then all done!}
{;}
/$E8/$05/$01 { call PopSt ;get regs set up for a compare call}
/$E8/$85/$00 { call Compare ;do compare for this substring set}
/$09/$D2 { or dx,dx ;if nothing in common}
{ ; then nothing to push}
/$74/$EE { jz Main ;try another set}
{;}
/$D1/$E2 { shl dx,1 ;*2}
/$01/$16/>SCORE { add [>score],dx ;add into score}
/$8B/$2E/>STCKNUM { mov bp,[>stcknum] ;get nr of entry}
{ ; I want to look at}
/$D1/$E5 { shl bp,1 ;get AX ready}
{ ; to access string stacks}
/$3E { DS: ;override SS:bp}
/$8B/$B6/>STSTR1L { mov si,[>ststr1L][bp] ;move L1 into SI or L1}
/$8B/$1E/>CL1 { mov bx,[>cL1] ;move CL1 into BX or R1}
/$3E { DS: ;override SS:bp}
/$8B/$BE/>STSTR2L { mov di,[>ststr2L][bp] ;move L2 into DI or L2}
/$8B/$0E/>CL2 { mov cx,[>cL2] ;move CL2 into CX temporarily}
/$3E { DS: ;override SS:bp}
/$8B/$86/>STSTR1R { mov ax,[>ststr1R][bp] ;get old R1 off of stack}
/$A3/>CL1 { mov [>cL1],ax ;place in CL1 temporarily}
/$3E { DS: ;override SS:bp}
/$8B/$86/>STSTR2R { mov ax,[>ststr2R][bp] ;get old R2 off of stack}
/$A3/>CL2 { mov [>cL2],ax ;save in CL2 temporarily}
/$89/$CD { mov bp,cx ;place CL2 into BP}
{;}
/$39/$F3 { cmp bx,si ;compare CL1 to L1}
/$74/$11 { je Chrght ;if zero, then nothing}
{; ; on left side str1}
/$39/$FD { cmp bp,di ;compare CL2 to L2}
/$74/$0D { je Chrght ;if zero, then nothing}
{; ; on left side str2}
/$4B { dec bx ;point to last part}
{ ; of left side str1}
/$4D { dec bp ;ditto, str2}
/$39/$F3 { cmp bx,si ;only one char to examine?}
/$75/$04 { jne PushIt ;no->we need to examine this}
/$39/$FD { cmp bp,di ; only one char in both?}
/$74/$03 { je Chrght ; nothing to look at}
{; ; if both only contain 1 char}
{PushIt:}
/$E8/$96/$00 { call PushSt ;push left side on stack}
{Chrght:}
/$8B/$36/>CR1 { mov si,[>cR1] ;move CR1 into SI or L1}
/$8B/$1E/>CL1 { mov bx,[>cL1] ;move R1 into BX or R1}
/$8B/$3E/>CR2 { mov di,[>cR2] ;move CR2 into DI or L2}
/$8B/$2E/>CL2 { mov bp,[>cL2] ;move R2 into BP or R2}
{;}
/$39/$DE { cmp si,bx ;compare CR1 to R1}
/$74/$95 { je Main ;If zero, then nothing}
{ ; on right side str1}
/$39/$EF { cmp di,bp ;compare CR2 to R2}
/$74/$91 { je Main ;if zero, then nothing}
{ ; on right side str2}
/$46 { inc si ;point to last part}
{ ; of right side str1}
/$47 { inc di ;ditto, str2}
/$39/$F3 { cmp bx,si ;only one char to examine?}
/$75/$04 { jne Push2 ;no-> examine it}
/$39/$FD { cmp bp,di ; only 1 char to examine in both?}
/$74/$87 { je Main ; yes-> get next string off of stack}
{;}